﻿using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Dyn.News.Routing;
using Orchard.Mvc.Routes;

namespace Dyn.News {
    public class Routes : IRouteProvider {
        private readonly ICategoryPathConstraint _categoryPathConstraint;

        public Routes(ICategoryPathConstraint categoryPathConstraint) {
            _categoryPathConstraint = categoryPathConstraint;
        }

        public void GetRoutes(ICollection<RouteDescriptor> routes) {
            foreach (var routeDescriptor in GetRoutes())
                routes.Add(routeDescriptor);
        }

        public IEnumerable<RouteDescriptor> GetRoutes() {
            return new[] {
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Admin/Category/Create",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "CategoryAdmin"},
                                                                                      {"action", "Create"}
                                                                                  },
                                                         new RouteValueDictionary(),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Admin/Category/{categoryId}/Edit",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "CategoryAdmin"},
                                                                                      {"action", "Edit"}
                                                                                  },
                                                         new RouteValueDictionary (),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Admin/Category/{categoryId}/Remove",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "CategoryAdmin"},
                                                                                      {"action", "Remove"}
                                                                                  },
                                                         new RouteValueDictionary (),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Admin/Category/{categoryId}",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "CategoryAdmin"},
                                                                                      {"action", "Item"}
                                                                                  },
                                                         new RouteValueDictionary (),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Admin/Category/{categoryId}/Article/Create",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "ArticleAdmin"},
                                                                                      {"action", "Create"}
                                                                                  },
                                                         new RouteValueDictionary (),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Admin/Category/{categoryId}/Article/{articleId}/Edit",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "ArticleAdmin"},
                                                                                      {"action", "Edit"}
                                                                                  },
                                                         new RouteValueDictionary (),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Admin/Category/{categoryId}/Article/{articleId}/Delete",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "ArticleAdmin"},
                                                                                      {"action", "Delete"}
                                                                                  },
                                                         new RouteValueDictionary (),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Admin/Category/{categoryId}/Article/{articleId}/Publish",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "ArticleAdmin"},
                                                                                      {"action", "Publish"}
                                                                                  },
                                                         new RouteValueDictionary (),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Admin/Category/{categoryId}/Article/{articleId}/Unpublish",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "ArticleAdmin"},
                                                                                      {"action", "Unpublish"}
                                                                                  },
                                                         new RouteValueDictionary (),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Admin/Category",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "CategoryAdmin"},
                                                                                      {"action", "List"}
                                                                                  },
                                                         new RouteValueDictionary(),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Category",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "Category"},
                                                                                      {"action", "List"}
                                                                                  },
                                                         new RouteValueDictionary(),
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "Archive/{*archiveData}",
                                                         new RouteValueDictionary {
                                                                                      {"categoryPath", ""},
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "Article"},
                                                                                      {"action", "ListByArchive"}
                                                                                  },
                                                         new RouteValueDictionary {
                                                                                      {"archiveData", new IsArchiveConstraint()}
                                                                                  },
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Route = new Route(
                                                         "{categoryPath}/Archive/{*archiveData}",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "Article"},
                                                                                      {"action", "ListByArchive"}
                                                                                  },
                                                         new RouteValueDictionary {
                                                                                      {"categoryPath", _categoryPathConstraint},
                                                                                      {"archiveData", new IsArchiveConstraint()}
                                                                                  },
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Priority = 11,
                                                     Route = new Route(
                                                         "{categoryPath}/rsd",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "RemoteCategoryPublishing"},
                                                                                      {"action", "Rsd"}
                                                                                  },
                                                         new RouteValueDictionary {
                                                                                      {"categoryPath", _categoryPathConstraint}
                                                                                  },
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                     Priority = 11,
                                                     Route = new Route(
                                                         "{categoryPath}/{postSlug}",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "Article"},
                                                                                      {"action", "Item"}
                                                                                  },
                                                         new RouteValueDictionary {
                                                                                      {"categoryPath", _categoryPathConstraint}
                                                                                  },
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 },
                             new RouteDescriptor {
                                                    Priority = 11,
                                                    Route = new Route(
                                                         "{categoryPath}",
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"},
                                                                                      {"controller", "Category"},
                                                                                      {"action", "Item"},
                                                                                      {"categoryPath", ""}
                                                                                  },
                                                         new RouteValueDictionary {
                                                                                      {"categoryPath", _categoryPathConstraint}
                                                                                  },
                                                         new RouteValueDictionary {
                                                                                      {"area", "Dyn.News"}
                                                                                  },
                                                         new MvcRouteHandler())
                                                 }
                         };
        }
    }
}